package cn.gson.crmdemo.model.service;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSONArray;

import cn.gson.crmdemo.model.dao.CaigouDao;
import cn.gson.crmdemo.model.dao.FkjhDao;
import cn.gson.crmdemo.model.dao.PurchaseDao;
import cn.gson.crmdemo.model.mapper.FkjhMapper;
import cn.gson.crmdemo.model.pojo.Getmoneyrecord;
import cn.gson.crmdemo.model.pojo.PaymentPlan;
import cn.gson.crmdemo.model.pojo.Purchase;
import cn.gson.crmdemo.model.pojo.Supplier;
import cn.gson.crmdemo.model.vo.FkjhVo;


@Service
@Transactional(rollbackFor=Exception.class)
public class FkjhService {
	@Autowired
	FkjhMapper fm;
	@Autowired
	FkjhDao fkdao;
	@Autowired
	PurchaseDao pudao;
	@Autowired
	CaigouDao cgdao;
	//查询付款计划
		public JSONArray fkjh(String fkDate,String gysName,Integer fkState){
			return fm.selectfkjh(fkDate,gysName,fkState);
			
		}
	//查询采购单
		public JSONArray selectcg() {
			return fm.selectcg();
		}
			
		//添加付款计划
		public void addfkjh(FkjhVo fo){
			PaymentPlan fkjh = new PaymentPlan();
			Purchase pu=new Purchase();
			pu.setPurchaseId(fo.getPurchaseId());
			fkjh.setPurchase(pu);
			fkjh.setFkDate(fo.getFkDate());
			fkjh.setFkPaid(fo.getFkPaid());
			fkjh.setFkPerson(fo.getFkPerson());
			fkjh.setFkState(fo.getFkState());
			fkjh.setFkState(0);
			fkdao.save(fkjh);
		}
		//修改付款计划
		public void xgfkjh(FkjhVo fo) {
			PaymentPlan pn =new PaymentPlan();
			pn=fkdao.findById(fo.getFkId()).get();
			pn.setFkDate(fo.getFkDate());
			pn.setFkPerson(fo.getFkPerson());
			fkdao.save(pn);
		}
		//修改状态
		public void xgzt(int a, int b ,int o) {
			PaymentPlan pn =new PaymentPlan();
			pn=fkdao.findById(a).get();
			Purchase pu=new Purchase();
			pn.setFkState(b);
			pu=cgdao.findById(o).get();
			pu.setPurchaseState(1);
			cgdao.save(pu);
			fkdao.save(pn);
		}
		//模糊查询
		public JSONArray selectsj(String rq) {
			return fm.selectsj(rq);
		}
		//是否付款
		public JSONArray selectfk(Integer p) {
			return fm.selectfk(p);
		}
		//根据供应商查询
		public JSONArray selectgys(String gys) {
			return fm.selectgys(gys);
			
		}
}
